<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Disapproved extends Backend {

	public function __construct()
	{
		parent::__construct();
		$this->lang->load('sites');
		$this->load->model(['site_model','sitecategory_model','siteproduct_model','siteuser_model','siteorder_model','sitedisapproved_model']);
		$this->data['page_home']  = lang('lang_dashboard');
		$this->data['page_title'] = lang('lang_site');
		$this->data['codetype'] = 
		[
			"policy_violation"=>"违反政策",
			"item_missing_required_attribute"=>"缺少必须属性",
			"image_link_broken"=>"图片无法打开"
		];
		
	}


	public function index($siteid)
	{

		$site=$this->site_model->getitembyid($siteid);
		if(!$site) die('error link');

		$this->data['nav']=$this->get_site_nav($site,5);

		
		$this->data['site']=$site;
		// Title
		$this->data['meta_title'] = $this->data['page_title'];

		// Breadcrumbs
		$this->data['array_breadcrumbs'] = array(
			$this->data['page_home']  => 'backend',
			$this->data['page_title'] => 'backend/sites/site',
			'SHOPPING错误'=>'backend/sites/disapproved'
		);



		$key=trim($this->input->get('keyword'));
		$code=trim($this->input->get('code'));
        $page=max(1,(int) $this->input->get('page'));        
        $pagesize=intval($this->input->get('pagesize'));
        if($pagesize){
            set_cookie("pagesize",$pagesize,60*60*24);
        }else{
            $pagesize=get_cookie("pagesize");
		}
		
		$page_data=$this->sitedisapproved_model->getpage($siteid,$page,$pagesize,$key,"",$code);
		$this->data['loglist']=$page_data["data"];
		$this->data['pager']=$page_data["pager"]; 
		$this->data['total']=$page_data["total"];
        $this->data['pages']=$page_data["pages"];
		$this->data['page']=$page;   
		   
		$codelist  = $this->sitedisapproved_model->getcodes($siteid);
		$this->data["codelist"]=$codelist;
		$this->data["code"]=$code;
		$keyword = array(
			'name'      => 'keyword',
			'id'        => 'keyword',
			'value'     =>  $key,
			'class'     =>  'form-control input-sm',
			'placeholder'=> '请输入关键字',
			'maxlength' => '100'
		);
		$this->data['keyword']=$keyword;
		$this->data['content_header_title'] = content_header_title($this->data['page_title'],$site['name'].' 用户');
		$this->data['content'] = 'sites/disapproved';

		$this->render();
	}


	
	
	public function newajaxdel()
	{

		$return=["status"=>1];
		$cid=$this->input->post("cid");
		

		$disapproved  = $this->sitedisapproved_model->getitembyid($cid);
		if(!$disapproved)
		{
			$return["status"]=0;
			$return["msg"]="记录不存在";	
		}
		else
		{
			$this->sitedisapproved_model->delitem($disapproved["id"]);
		}
        echo json_encode($return);
		die();
	}


	public function ajaxdel()
	{

		$return=["status"=>1];
		$cid=$this->input->post("cid");
		

		$disapproved  = $this->sitedisapproved_model->getitembyid($cid);
		if(!$disapproved)
		{
			$return["status"]=0;
			$return["msg"]="记录不存在";	
		}
		else
		{
			$product=$this->siteproduct_model->getitemkeyfilter(["siteid"=>$disapproved["siteid"],"productid"=>$disapproved["prid"]]);
			if(!$product)
			{
				$return["status"]=0;
				$return["msg"]="产品记录不存在";			
			}
			else
			{
				$site=$this->site_model->getitembyid($product["siteid"]);
				loadsystemlink($site);
				if(!$this->mysite->checklink)
				{
					$return["status"]=0;
					$return["msg"]="请检查接口配置";	
				}
				else
				{
					$result = $this->mysite->delproduct($product);
					if($result=="ok")
					{
						$this->siteproduct_model->delitem($product["id"]);
						$this->sitedisapproved_model->delitem($disapproved["id"]);
					}
				}
			}
		}
        echo json_encode($return);
		die();
	}

}
